package com.ztesoft.report.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ztesoft.report.base.pojo.R;
import com.ztesoft.report.dao.SysSqlDao;
import com.ztesoft.report.entity.SysSql;
import com.ztesoft.report.service.SysSqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * SQL配置 服务实现类
 * </p>
 *
 * @author y3tu
 * @since 2018-06-14
 */
@Service
public class SysSqlServiceImpl implements SysSqlService {
    @Autowired
    SysSqlDao sysSqlDao;

    @Override
    public Map queryPage(Map<String, Object> map) {
        int current = (int) map.get("current");
        int size = (int) map.get("size");
        PageHelper.startPage(current, size);
        List<SysSql> list = sysSqlDao.queryPage(map);
        PageInfo<SysSql> page = new PageInfo<>(list);
        return R.ok(page);
    }

    @Override
    public Map getDataSourceList() {
        List<Map<String, Object>> list = sysSqlDao.getDataSourceList();
        return R.ok(list);
    }

    @Override
    public Map addSysSqlRow(SysSql sysSql) {
        sysSql.setCreateDate(new Date());
        sysSqlDao.addSysSqlRow(sysSql);
        return R.ok();
    }

    @Override
    public Map updateSysSqlRow(SysSql sysSql) {
        sysSql.setUpdateDate(new Date());
        sysSqlDao.updateSysSqlRow(sysSql);
        return R.ok();
    }

    @Override
    public Map removeSysSqlRow(SysSql sysSql) {
        sysSql.setUpdateDate(new Date());
        sysSqlDao.removeSysSqlRow(sysSql);
        return R.ok();
    }


}
